﻿<UserControl x:Class="Flipbook.Controls.RadialViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:InputInteractivity="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:Framework="clr-namespace:Flipbook.Framework"
             xmlns:Behaviors="clr-namespace:Flipbook.Behaviors"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300" 
             HorizontalContentAlignment="Stretch"
             VerticalContentAlignment="Stretch"
             x:Name="UserControl">
    <Grid>
        <ListBox x:Name="RadialCanvasListBox"
                 ItemsSource="{Binding CanvasViewModels}"
                 SelectedItem="{Binding ActiveCanvasViewModel}">
            <ListBox.Resources>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Canvas.ZIndex"
                            Value="0" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected"
                                 Value="True">
                            <Setter Property="Canvas.ZIndex"
                                    Value="1" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.Resources>
            <ListBox.Template>
                <ControlTemplate>
                    <Border>
                        <ScrollViewer Focusable="False"
                                      Padding="{TemplateBinding Padding}">
                            <Framework:CircularPanel IsItemsHost="True"
                                                     IsAnimated="True"
                                                     Align="Left"
                                                     Radius="100"
                                                     AngleItem="15"
                                                     InitialAngle="135"
                                                     AnimationDuration="50"
                                                     Height="{Binding ElementName=UserControl, Path=Height}"
                                                     Width="{Binding ElementName=UserControl, Path=Width}"/>

                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ListBox.Template>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border Canvas.ZIndex="0"
                            BorderThickness="1"
                            BorderBrush="Black"
                            Width="400"
                            Height="400">
                        <Border.Background>
                            <VisualBrush Visual="{Binding Canvas}" />
                        </Border.Background>
                    </Border>                    
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ListBox>
        <i:Interaction.Behaviors>
            <Behaviors:GestureToCommandBehavior SupportedGestures="Tap"
                                                Command="{Binding ElementName=UserControl, Path=CloseCommand}" />
        </i:Interaction.Behaviors>
    </Grid>
</UserControl>
